<html><body><pre>
<script>
Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
}
Array.method('reduce', 
    function(f) {
        var res = (arguments.length == 2) ? arguments[1] : null;
        for (var i=0; i<this.length; i++) {
            res = f(this[i], res);
        }    
        return res;
    }
);

function sum(a) {
    var b = ((arguments.length == 2) && arguments[1]) ? arguments[1] : 0;
    return a+b;
}    
    
var v = [2, 3, 5, 8];
document.writeln(v.reduce(sum));
document.writeln(v.reduce(sum, 1000));

</script>
</pre></body></html>
